package xyc.szk.web.servlet.response;
/*
 * @Description: 响应器
 * @Author: 山志凯
 * @Date: 2021-04-07
 * @Time: 08:27
 */

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

@WebServlet("/resp03")
public class ResponseServlet03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        //响应器：字符响应器；
        //      字节响应器（二进制编码），如图片，文件的下载等

        //1、字符流响应器
        PrintWriter pw = resp.getWriter();
        pw.write("<h1>我是字符流响应器</h1>"); //即想浏览器发送一个信息--响应

        //2、字节流响应器
        ServletOutputStream out = resp.getOutputStream();
        out.write("<h1>我是字符流响应器</h1>".getBytes());
        //out.write(new String("<h1>我是字符流响应器</h1>".getBytes(),StandardCharsets.ISO_8859_1));
    }
}
